# Django settings for app_submission project.
import os
import djcelery
djcelery.setup_loader()

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP

DEBUG = True
TEMPLATE_DEBUG = DEBUG

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Asia/Chongqing'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = False

DATETIME_FORMAT = 'Y-m-d H:i:s'
DATE_FORMAT = 'Y-m-d'
TIME_FORMAT = 'H:i:s'
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, '../media').replace('\\', '/')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, '../static').replace('\\', '/'),
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'z7^zyf4!_qua-)k=zpna&dg7&6*)sb+x-e2m2(3e=adhlxvpm%'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',

    'core.middleware.CustomMiddleware',
)

ROOT_URLCONF = 'urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'wsgi.application'

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, '../templates').replace('\\', '/'),
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

IMPORTED_APPS_DIR = os.path.join(BASE_DIR, '../imported_apps').replace('\\', '/')

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'suit',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    'app_info',
    'accounts',
    'ads_info',
    'iap_info',
    'core',
    'sub_info',
    'prj_tracker',
    'appleid_info',
    'notification',
    'version',
    'prd_order',
    'qa_info',
    'sdk_info',

    'djcelery',
    'sorl.thumbnail',
    'south',
    'production_kanban'
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

TEMPLATE_CONTEXT_PROCESSORS = TCP + (
    "django.core.context_processors.request",

    "core.context_processors.get_unread_count",
)

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

# extra configs, must be overrided
CHECK_URL = ''
WRITER_EMAIL = ''
WRITER_PWD = ''
FILE_NAME = ''
ADS_REQUEST_FILE = ''
SUB_REQUEST_FILE = ''
ADS_ID_FILE = ''

# gmail configs
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_SUBJECT_PREFIX = '[PTS]'

EMAIL_HTML_TEMPLATE = '''<p><font size=10>{0}</font></p>
                         <p>App Code: <font color='red'>{1}</font></p>
                         <p>App Name: <font color='red'>{2}</font></p>
                         <p>Full Bundle ID: <font color='red'>{3}</font></p>
                         <p>App ID: <font color='red'>{4}</font></p>
                         <p>Notes: <font color='red'>{5}</font></p>'''

# oauth configs, must be overrided
CLIENT_ID = ''
CLIENT_SECRET = ''
AUTH_URL = ''
GET_TOKEN_URL = ''
REDIRECT_URL = ''

APP_LABEL_LOCAL = {'app_info': 'App Registration', 'ads_info': 'Ad Ops',
                   'iap_info': 'IAP Setup', 'auth': 'Authorization',
                   'sub_info': 'App Submission', 'prj_tracker': 'Production Tracker',
                   'appleid_info': 'Analytical Tools',
                   'notification': 'Notification', 'version': 'PTS Version',
                   'prd_order': 'Production Order', 'qa_info': 'QA Tracker',
                   'sdk_info': 'SDK Management'}

# Django Suit configs
SUIT_CONFIG = {
    'ADMIN_NAME': 'Production Tracking System',
    'HEADER_DATE_FORMAT': 'Y-m-d, D',

    'CONFIRM_UNSAVED_CHANGES': False,
    'MENU_EXCLUDE': ('sites',),
    'SEARCH_URL': '',

    'MENU': (
        {'label': 'Production Kanban Board', 'icon': 'icon-signal', 'models':({'label':'Production Kanban Board','url': '/production_kanban'},) , 'permissions': ('notification.change_notice',),},
        # {'app': 'notification', 'label': APP_LABEL_LOCAL.get('notification'), 'models': ({'model': 'notice', 'label': 'Notification'},), 'icon': 'icon-envelope'},
        {'app': 'auth', 'label': APP_LABEL_LOCAL.get('auth'), 'models': ('app_info.company', 'user', {'model': 'group', 'label': 'Permission Groups'}, 'notification.reportreceiver',), 'icon': 'icon-user'},
        {'label': 'Studio Assignment', 'icon': 'icon-pencil', 'models': ('app_info.studio', 'app_info.productionteam',), 'permissions': ('app_info.change_studio',),},
        {'app': 'sdk_info', 'label': APP_LABEL_LOCAL.get('sdk_info'), 'icon': 'icon-briefcase'},
        # {'app': 'prd_order', 'label': APP_LABEL_LOCAL.get('prd_order'), 'models': ('productionorder',), 'icon': 'icon-list-alt'},
        
        # heyulin 2016-3-18
        # {'app': 'prj_tracker', 'label': APP_LABEL_LOCAL.get('prj_tracker'), 'models': ({'model': 'app_info.appversion', 'label': 'Production Output Tracker'},), 'icon': 'icon-tasks'},
        # {'app': 'app_info', 'label': APP_LABEL_LOCAL.get('app_info'), 'models': ('app', 'appleid')},
        {'label': 'App Registration', 'models': ({'model': 'app_info.app', 'label': 'Apps'},{'model':'app_info.appversion','label':'App Versions'})},      
        
        {'app': 'ads_info', 'label': APP_LABEL_LOCAL.get('ads_info'), 'models': ('adsinfo', 'network')},
        {'app': 'iap_info', 'label': APP_LABEL_LOCAL.get('iap_info'), 'models': ('iapinfo', 'publickey')},
        {'label': 'Cross Promo', 'models': ({'model': 'ads_info.crosspromoreq', 'label': 'Cross Promo Requests'}, {'model': 'ads_info.crosspromovendor', 'label': 'Cross Promo Vendors'},)},
        {'app': 'appleid_info', 'label': APP_LABEL_LOCAL.get('appleid_info'), 'models': ('app_info.flurrykey', 'app_info.gakey', 'app_info.quantcastkey')},
        {'app': 'qa_info', 'label': APP_LABEL_LOCAL.get('qa_info'), 'models': ('devqainfo', 'releaseqainfo')},

        {'label': 'QA Kanban Board', 'models': ({'label': 'QA Kanban Board', 'url': 'get_qa_kanban'},), 'permissions': ('notification.change_notice',),},

        {'app': 'sub_info', 'label': APP_LABEL_LOCAL.get('sub_info'), 'models': ('subinfo',)},
#        {'app': 'version', 'label': APP_LABEL_LOCAL.get('version')},
        # custom menu
        {'label': 'Meta Data', 'blank': True, 'url': 'go_ps'},
        {'label': 'Report Center', 'icon': 'icon-signal', 'models': ({'label': 'Production Output Report', 'url': 'get_production_output'},), 'permissions': ('notification.change_notice',),},
        
    )
}

# celery configs
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
#BROKER_URL = 'amqp://guest:guest@localhost:5672//'
#CELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//'

# exported apps file
EXPORTED_APPS_DIR = os.path.join(BASE_DIR, '../exported_apps').replace('\\', '/')

# uploaded image folder
REJ_IMG_DIR = 'rej_img/'

# TMS (Talent Management System) api config
TMS_DOMAIN = 'http://tms.mokitech.com'
TMS_GET_STAFFING = '/get_staff/'

# PS (Publish System) api config
PS_DOMAIN = 'http://ps.mokitech.com'
PS_CREATE_APP = '/create_new_app/'
PS_CANCEL_APP = '/update_new_app/'
PS_CREATE_SUB = '/create_submission/'
PS_CANCEL_SUB = '/cancel_submission/'
PS_CREATE_META = '/create_metadata/'
PS_DO_LOGIN = '/do_login/'

# APM api config
APM_DOMAIN = 'http://apm.stm.com'
APM_NEW_RELEASED = '/app_info/new/register/'
